package activator;

import java.util.Dictionary;
import java.util.Hashtable;

import library.service.LibraryService;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;

import service.factory.LibraryServiceFactory;

public class Activator implements BundleActivator {

	private static final int LIBRARY_SERVICES_COUNT = 2;
	private static int counter = 1;

	public void start(BundleContext bundleContext) throws Exception {
		System.out.println("LOADER ServiceFactory:  START() method, counter= "
				+ counter);
		LibraryServiceFactory libServiceFactory = new LibraryServiceFactory();

		for (; counter <= LIBRARY_SERVICES_COUNT; counter++) {
			Dictionary libServiceFactoryProps = new Hashtable();
			libServiceFactoryProps.put("counter", new Integer(counter));

			System.out.println("LOADER ServiceFactory: " + counter
					+ " LibraryService registered");
			ServiceRegistration serviceReg = bundleContext.registerService(
					LibraryService.class.getName(), libServiceFactory,
					libServiceFactoryProps);
			System.out.println("LOADER ServiceFactory: " + counter
					+ " serviceReg= " + serviceReg); 
		}

	}

	public void stop(BundleContext context) throws Exception {
		System.out.println("LOADER ServiceFactory:  STOP() method");
	}

}
